//
//  WeaponEntity.m
//  pig
//
//  Created by shanshan on 10-6-8.
//  Copyright 2010 __MyCompanyName__. All rights reserved.
//

#import "WeaponEntityView.h"


@interface WeaponEntityView(Private)

-(void)initArrow;
-(void)initKnife;
-(void)initStone;

@end

@implementation WeaponEntityView

#pragma mark -
#pragma mark init

-(id)init{
	CMLog(@"in WeaponEntityView init");
	if( (self=[super init]) ) {
		[self initArrow];
		[self initKnife];
		[self initStone];
		//Set the display frame of your sprite using idle animation
		//[mySprite setDisplayFrame:@"idle" index:0]; //display idle1.png
		//	[mySprite setDisplayFrame:@"idle" index:1]; //display idle2.png
	}
	//[self addTailParticleSun];
	return self;
	
}

#pragma mark -
#pragma mark init Animation
-(void)initKnife{
	CCAnimation *animation = [[CCAnimation alloc] initWithName:@"knife" delay:0];
	[animation addFrameWithFilename:@"knife1.png"];
	[animation addFrameWithFilename:@"knife2.png"];
	[animation addFrameWithFilename:@"knife3.png"];
	[animation addFrameWithFilename:@"knife4.png"];
	[animation addFrameWithFilename:@"knife5.png"];
	[animation addFrameWithFilename:@"knife6.png"];
	[animation addFrameWithFilename:@"knife7.png"];
	[animation addFrameWithFilename:@"knife8.png"];
	[animation addFrameWithFilename:@"knife9.png"];
	[animation addFrameWithFilename:@"knife10.png"];
	[animation addFrameWithFilename:@"knife11.png"];
	[animation addFrameWithFilename:@"knife12.png"];
	[animation addFrameWithFilename:@"knife13.png"];
	[animation addFrameWithFilename:@"knife14.png"];
	[animation addFrameWithFilename:@"knife15.png"];
	[animation addFrameWithFilename:@"knife16.png"];
	[animation addFrameWithFilename:@"knife17.png"];
	[animation addFrameWithFilename:@"knife18.png"];
	[animation addFrameWithFilename:@"knife19.png"];
	[animation addFrameWithFilename:@"knife20.png"];
	[animation addFrameWithFilename:@"knife21.png"];
	[animation addFrameWithFilename:@"knife22.png"];
	[animation addFrameWithFilename:@"knife23.png"];
	[animation addFrameWithFilename:@"knife24.png"];
	[self addAnimation:animation];
	[animation release];
}

-(void)initStone{
	CCAnimation *animation = [[CCAnimation alloc] initWithName:@"stone" delay:0];
	[animation addFrameWithFilename:@"shi1.png"];
	[animation addFrameWithFilename:@"shi2.png"];
	[animation addFrameWithFilename:@"shi3.png"];
	[animation addFrameWithFilename:@"shi4.png"];
	[animation addFrameWithFilename:@"shi5.png"];
	[animation addFrameWithFilename:@"shi6.png"];
	[animation addFrameWithFilename:@"shi7.png"];
	[animation addFrameWithFilename:@"shi8.png"];
	[self addAnimation:animation];
	[animation release];
}

-(void)initArrow{
	CCAnimation *animation = [[CCAnimation alloc] initWithName:@"arrow" delay:0];
	[animation addFrameWithFilename:@"arrow.png"];
	[self addAnimation:animation];
	[animation release];
}

- (void)fireStoneToPosition:(CGPoint)playerPosition{
	CMLog(@"startStone in WeaponEntityView");
	id stone =[CCAnimate actionWithDuration:3.0f animation:[self animationByName:@"stone"] restoreOriginalFrame:NO];
	
	id throwStone = [CCJumpBy actionWithDuration:2.0f position:playerPosition height:-50.0f jumps:1];
	
	id delete =[CCCallFunc actionWithTarget:self selector:@selector(delete)];
	
	CCSpawn *move = [CCSpawn actions:  stone,
					 [CCSequence actions: throwStone, delete, nil], 
					 nil];
	[self runAction:move];
	
}

- (void)fireArrow{
	CMLog(@"startArrow in WeaponEntityView");
	id arrow =[CCAnimate actionWithDuration:2.0f animation:[self animationByName:@"arrow"] restoreOriginalFrame:NO];
	
	id delete =[CCCallFunc actionWithTarget:self selector:@selector(delete)];
	
	CCSpawn *move = [CCSpawn actions:  
					 [CCMoveBy actionWithDuration:2.0f position:ccp(-300,0)],
					 [CCSequence actions: arrow, delete, nil], 
					 nil];
	[self runAction:move];
	
}

@end
